<form id="authseditfm" method="post" style="padding:0 8px 0 0;">
    <input type="hidden" name="id" value="<?php echo $dataset->id;?>"/>
    <table border="0" width="100%" cellspacing="1" cellpadding="5" class="formtable">
        <tr bgcolor="#FFFFFF">
            <td class="tlabel" width="10%">所属权限组：</td>
            <td width="90%">
                <select name="up" class="forminput inputstyle">
                    <option value=0>--根权限--</option>
                    <option disabled>----------</option>
                    <?php foreach($rootlevel as $v): ?>
                    <option
                    <?php if($v->id==$dataset->up){echo 'selected';}?> value="<?php echo $v->id;?>"><?php echo $v->authname;?></option>
                    <?php endforeach; ?>
                </select>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td class="tlabel">权限名称：</td>
            <td><input name="authname" type="text" style="width:400px;" class="forminput inputstyle validatebox-text textbox-prompt easyui-validatebox" placeholder="自定义权限名称.." required="true" value="<?php echo $dataset->authname;?>"></td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td class="tlabel">控制器：</td>
            <td>
                <select name="controller" onchange="getAct(this.value);" class="forminput inputstyle">
                    <option value=''>--根权限不用选择控制器--</option>
                    <?php foreach($controllers as $v): ?>
                    <option
                    <?php if($v==$dataset->controller){echo 'selected';}?> value="<?php echo $v;?>"><?php echo $v;?></option>
                    <?php endforeach; ?>
                </select>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td class="tlabel">方法：</td>
            <td>
                <div id="action">
                    <?php foreach($actrows as $v): ?>
                    <label style='width:160px;float:left;display:block;font-weight:100;'><input type='checkbox' <?php if($v['flag']==1){echo 'checked';}?> name='action[]' value='<?php echo $v['act'];?>'><?php echo $v['act'];?></label>
                    <?php endforeach; ?>
                </div>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td class="tlabel">排序：</td>
            <td>
                <input type="text" name="sortorder" value="<?php echo $dataset->sortorder;?>"/>
            </td>
        </tr>
        <tr>
            <td colspan="2" bgcolor="#F4F4F4" style="border-top:#ddd 1px solid;text-align:right; padding-right:25px;">
                <div>
                    <a href="javascript:;" class="l-btn l-btn-small" onclick="authseditsubmitForm()"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">保存</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>
                    <a href="javascript:;" class="l-btn l-btn-small" onclick="authseditclearForm()"><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">关闭</span><span class="l-btn-icon icon-no">&nbsp;</span></span></a>
                </div>
            </td>
        </tr>
    </table>
</form>

<script>
    var getAct = function (ctl) {
        $.get('/admin/system/getacts?controller=' + ctl, function (data) {
            var act = '';
            $.each(data.data, function (key, value) {
                act += "<label style='width:160px;float:left;display:block;font-weight:100;'><input type='checkbox' name='action[]' value='" + value + "'>" + value + "</label>";
            });
            $('#action').html(act);
        }, 'json');
    };
    var authseditclearForm = function () {
        $('#newsaddfm').form('clear');
        $('#rightTabs').tabs('close', '权限编辑');
    };
    var authseditsubmitForm = function (data) {
        $('#authseditfm').form('submit', {
            url: '/admin/system/authsupdate',
            success: function (data) {
                var data = eval('(' + data + ')');

                if (data.code == '200') {
                    $.messager.show({
                        title: '提示',
                        msg: data.msg,
                        timeout: 3000,
                        showType: 'slide'
                    });
                    $("#auths").treegrid('reload');
                } else {
                    var msginfo = '';
                    if (data.data != '') {
                        var n = 1;
                        $.each(data.data, function (k, v) {
                            msginfo += n + '.' + v + '<br>';
                            n++;
                        });
                    }
                    $.messager.alert('提示', data.msg + '<br>' + msginfo, 'warning');
                }
            }
        });
    };
</script>
